﻿// simplejson.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <string>
#include <fstream>
#include "json.h"

using namespace std;
using namespace SimpleJson;

int main()
{
    ifstream ifs("out1.json");
    JsonParser parser(ifs);
    if (parser.succeed())
    {
        string json_str;
        parser.toString(json_str, true);
        cout << json_str << endl;

        Json& root = parser.getRoot();
        int id = root["id"].asInt();
        cout << "id = " << id << endl;
        root["id"] = 567;
        id = root["id"].asInt();
        cout << "id = " << id << endl;
        string layer = root["friend"]["layers"][1].asString();
        cout << layer << endl;

        root["friend"]["layers"][1] = "relu";
        parser.toString(json_str, true);
        cout << json_str << endl;

        root["friend"]["layers"].clear();
        parser.toString(json_str, true);
        cout << json_str << endl;

        root["author"] = "lanxb";
        parser.toString(json_str, true);
        cout << json_str << endl;

        if (root["optimizers"].setArray(3))
        {
            parser.toString(json_str, true);
            cout << json_str << endl;
        }
        root["optimizers"][0] = "GradDescent";
        root["optimizers"][1] = "Momentumn";
        root["optimizers"][2] = "AdaGrad";
        parser.toString(json_str, true);
        cout << json_str << endl;

        parser.save("out2.json", true);
    }
    ifs.close();

    return 0;
}



